{% extends 'layout.html' %}

{# Set variables for base layour #}
{% set active_page = "communities" %}
{% set title = 'List of communities' %}

{% block content %}

    {% for community in communities|sort(attribute="name")|sort(attribute="members_count", reverse=True) %}
        <p>
            <div><a href="{{ url('community', cmty=community['name']) }}" title="{{ community['members_count'] }} members">{{ community["name"] }} ({{ community['members_count'] }} 👤)</a></div>
            <div>{{ community["description"] }}</div>
        </p>
    {% endfor %}

    <br /><br />

    {% if user %}
    {# onkeydown="" prevents submitting the form by pressing Enter (user must click submit button) #}
    <form action="{{ url('communities') }}" method="post" onkeydown="return event.key != 'Enter';">
        <input type="text" class="form-control form-control-inline" name="community_name" placeholder="community name" required minlength="3" maxlength="100" pattern="[^\s]+" />
        <input type="submit" class="button button_info" value="Create new community" />
    </form>
    {% endif %}

{% endblock %}
